# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
@good = (uid,otherid,aid,qid,obj)->
  $(obj).removeAttr 'onclick'
  if uid==0
    alert "请先登录"
    document.location.href = '/login'
    return;
  if uid==otherid
    alert '赞自己失败'
    return;
  $.ajax '/praises',
    type:'post'
    data:{praise:{user_id:uid,answer_id:aid,question_id:qid,other_id:otherid}}
    dataType:'json'
    success:(data,textStatus,jqXHR)->
      if data.stat==1
        $(obj).parent().find('.praise-num').html(parseInt($(obj).parent().find('.praise-num').html())+1)
      if data.stat==2
        alert "已赞过"
